package org.kgc.alanhealth.service.impl;

import org.kgc.alanhealth.entity.HospitalForum;
import org.kgc.alanhealth.mapper.HospitalForumMapper;
import org.kgc.alanhealth.mapper.HospitalCommentsMapper;
import org.kgc.alanhealth.service.ForumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ForumServiceImpl implements ForumService {

    @Autowired
    private HospitalForumMapper hospitalForumMapper;

    @Autowired
    private HospitalCommentsMapper hospitalCommentsMapper;

    @Override
    public int insertAndUpdate(HospitalForum record) {
        // 设置评论时间
        record.setCommenttime(new Date());

        // 插入数据到 hospital_forum 表
        int i=hospitalForumMapper.insert(record);

        // 更新 hospital_comments 表中的 replyDate
        hospitalCommentsMapper.updateReplyDate(record.getPostnumber(), record.getCommenttime());
        return i;
    }
}
